//
//  SearchDataViewCell.m
//  NewMyMusicAPP
//
//  Created by 08- 张志强 on 15/6/26.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "SearchDataViewCell.h"

@implementation SearchDataViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self searchMake];
    }
    
    return self;
}

-(void)searchMake
{
    

    
    self.albumImg = [[UIImageView alloc]init];
    self.albumImg.frame=CGRectMake(WIDTH * 5,HEIGHT * 5,WIDTH * 170,HEIGHT * 100);
    self.albumImg.contentMode = UIViewContentModeScaleToFill;
    [self.albumImg setClipsToBounds:YES];
    [self.albumImg setContentMode:UIViewContentModeScaleToFill];
    [self.contentView addSubview:self.albumImg];
    
    self.titleLable = [[[UILabel alloc]initWithFrame:CGRectMake(WIDTH * 190,HEIGHT * 35,WIDTH * 190,HEIGHT * 30)]autorelease];
    self.titleLable.backgroundColor=[UIColor clearColor];
    self.titleLable.font=[UIFont systemFontOfSize:14];
    self.titleLable.text=@"465";
    self.titleLable.numberOfLines=0;
    self.titleLable.textColor=[UIColor whiteColor];
    self.titleLable.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:self.titleLable];
    
    self.artistNameLable= [[[UILabel alloc]initWithFrame:CGRectMake(WIDTH * 190,HEIGHT * 70,WIDTH * 190,HEIGHT * 30)]autorelease];
    self.artistNameLable.backgroundColor=[UIColor clearColor];
    self.artistNameLable.font=[UIFont systemFontOfSize:14];
    self.artistNameLable.text=@"4444444";
    self.artistNameLable.numberOfLines=0;
    self.artistNameLable.textColor=[UIColor orangeColor];
    self.artistNameLable.textAlignment=NSTextAlignmentLeft;
    [self addSubview:self.artistNameLable];
    
    //收藏按钮
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(WIDTH * 330, HEIGHT * 5, WIDTH * 27, WIDTH * 25);
    [self.button addTarget:self action:@selector(collect) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
    
    
}

-(void)setSearchModel:(SearchDataModel *)searchModel
{
    NSLog(@"走吧走吧走吧");
    if (_searchModel != searchModel) {
        [_searchModel release];
        _searchModel = [searchModel retain];
    }
    self.titleLable.text=self.searchModel.title;
    self.artistNameLable.text = self.searchModel.artistName;
    
    //判断有没有高清图片
    if (self.searchModel.albumImg.length == 0) {
        NSURL *url = [NSURL URLWithString:self.searchModel.posterPic];
        [self.albumImg sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_discover_moment@3x.png"]];
        
    }else{
        
        NSURL *url = [NSURL URLWithString:self.searchModel.albumImg];
        [self.albumImg sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_discover_moment@3x.png"]];
    }
    
    //收藏图片
    if (self.buer == YES) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@3x.png"] forState:UIControlStateNormal];
        
        
    }else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@2x.png"] forState:UIControlStateNormal];
        
    }

    
    
    
    
    
    
}

-(void)collect
{
    CollectModel *collect = [[[CollectModel alloc] init]autorelease];
    collect.title = self.searchModel.title;
    collect.modelId = self.searchModel.idd;
    collect.type = @"VIDEO";
    // NSLog(@"asdasdasd = %@ %@ %@",collect.modelId,collect.type,collect.title);
    
    
    if (self.buer == NO) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@3x.png"] forState:UIControlStateNormal];
        [[DataHandle shareHandleController] insertCollect:collect];
        self.buer = YES;
        NSLog(@"添加收藏 NO  ==  id = %@",collect.modelId);
    }else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@3x.png"] forState:UIControlStateNormal];
        [[DataHandle shareHandleController] deleteTable:collect.modelId];
        self.buer = NO;
        NSLog(@"删除收藏 YES ==  id = %@",collect.modelId);
    }
    
    
}







- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
